package com.hqd.jjvm.classformat.constantpool;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.util.HexStrTransformUtil;
import lombok.Getter;

import java.util.List;

@Getter
public class ConstantStringInfo extends ConstantPool {
	private Integer stringIndex;


	public ConstantStringInfo(ConstantInfoType tag, ClassFile classFile) {
		super(tag, classFile);
		this.stringIndex = HexStrTransformUtil.parseHexToInt(classFile.readU2());
		checkPoolIndex(stringIndex);
	}

	@Override
	public String getVal() {
		List<ConstantPool> constantPools = classFile.getConstantPools();
		ConstantUtf8Info utf8Info = (ConstantUtf8Info) constantPools.get(stringIndex);
		return utf8Info.getVal();
	}
}
